﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace RelightERP.BLL
{
    public static class ExtensionMethods
    {
        #region SQLDataSource

        #region SetConnString
        public static void SetConnString(this SqlDataSource sqlDataSource)
        {
            sqlDataSource.ConnectionString = DefaultHelper.GetConnString();
        }
        #endregion

        #region SetSelectCommand
        public static void SetSelectCommand(this SqlDataSource sqlDataSource, bool isStoredProc, string sqlID, List<Parameter> list)
        {
            sqlDataSource.SelectCommand = DefaultHelper.GetSql(sqlID);
            if (isStoredProc)
            {
                sqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            }
            else
            {
                sqlDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
            }
            if (list != null && list.Count != 0)
            {
                list.ForEach(p =>
                {
                    sqlDataSource.SelectParameters.Add(p);
                }
                            );
            }
        }
        #endregion

        #region SetSelectCommand
        //public static void SetSelectCommand(this SqlDataSource sqlDataSource, bool isStoredProc, string sReportID, string sSqlID, List<Parameter> list)
        //{
        //    sqlDataSource.SelectCommand = BaseHelper.GetReportSql(sReportID, sSqlID);
        //    if (isStoredProc)
        //    {
        //        sqlDataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
        //    }
        //    else
        //    {
        //        sqlDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
        //    }
        //    if (list != null && list.Count != 0)
        //    {
        //        list.ForEach(p =>
        //        {
        //            sqlDataSource.SelectParameters.Add(p);
        //        }
        //                    );
        //    }
        //}
        #endregion

        #region SetInsertCommand
        public static void SetInsertCommand(this SqlDataSource sqlDataSource, bool isStoredProc, string sqlID, List<Parameter> list)
        {
            sqlDataSource.InsertCommand = DefaultHelper.GetSql(sqlID);
            if (isStoredProc)
            {
                sqlDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure;
            }
            else
            {
                sqlDataSource.InsertCommandType = SqlDataSourceCommandType.Text;
            }
            if (list != null && list.Count != 0)
            {
                list.ForEach(p =>
                {
                    sqlDataSource.InsertParameters.Add(p);
                }
                            );
            }
        }
        #endregion

        #region SetUpdateCommand
        public static void SetUpdateCommand(this SqlDataSource sqlDataSource, bool isStoredProc, string sqlID, List<Parameter> list)
        {
            sqlDataSource.UpdateCommand = DefaultHelper.GetSql(sqlID);
            if (isStoredProc)
            {
                sqlDataSource.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
            }
            else
            {
                sqlDataSource.UpdateCommandType = SqlDataSourceCommandType.Text;
            }
            if (list != null && list.Count != 0)
            {
                list.ForEach(p =>
                {
                    sqlDataSource.UpdateParameters.Add(p);
                }
                            );
            }
        }
        #endregion

        #region SetDeleteCommand
        public static void SetDeleteCommand(this SqlDataSource sqlDataSource, bool isStoredProc, string sqlID, List<Parameter> list)
        {
            sqlDataSource.DeleteCommand = DefaultHelper.GetSql(sqlID);
            if (isStoredProc)
            {
                sqlDataSource.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;
            }
            else
            {
                sqlDataSource.DeleteCommandType = SqlDataSourceCommandType.Text;
            }
            if (list != null && list.Count != 0)
            {
                list.ForEach(p =>
                {
                    sqlDataSource.DeleteParameters.Add(p);
                }
                            );
            }
        }
        #endregion

        #endregion
    }
}
